using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using gudusoft.gsqlparser;
using gudusoft.gsqlparser.Units;


namespace customizedColor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //define color of user customized token
            lzbasetype.gFmtOpt.HighlightingElements[(int)TLzHighlightingElement.sfkUserCustomized].SetForegroundInRGB("#FF00FF");
            
            TGSqlParser parser = new TGSqlParser(TDbVendor.DbVOracle);
            parser.SqlText.Text = txtInput.Text;

            // do some source token modification before generate output
            parser.BeforeGenerateFormattedSQL += new TBeforeGenerateFormattedSQL(doBeforeGenerateFormattedSQL);

            rtfOutput.Rtf = parser.ToRTF(TOutputFmt.ofrtf);
        }
        
        static void doBeforeGenerateFormattedSQL(object sender)
        {
            TGSqlParser parser = (TGSqlParser)sender;
            foreach (TSourceToken st in parser.SourceTokenList)
            {
//                if ((st.TokenType == TTokenType.ttIdentifier) && (st.AsText.Equals("?"))){
                if ((st.AsText.Equals("?"))){
                    st.AsText = "param";
                    //set this token to user customized, so it can be shown in color we set.
                    st.TokenType = TTokenType.ttUserCustomized;
                }
            }
        }
    }
}